package com.nami.web.controller;

import com.nami.common.domain.pojo.SysMenu;
import com.nami.common.domain.pojo.SysUser;
import com.nami.common.utils.SecurityUtils;
import com.nami.system.service.ISysMenuService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Slf4j
@RestController
@RequiredArgsConstructor
public class IndexController {

    private final ISysMenuService menuService;
    @GetMapping("/index")
    public ModelAndView index() {
        ModelAndView modelAndView = new ModelAndView("index");
        SysUser user = SecurityUtils.getUserInfo();
        log.info("user: {}", user);
        List<SysMenu> menus = menuService.getTreeMenuByUserId(user.getId());
        modelAndView.addObject("user", user);
        modelAndView.addObject("menus", menus);
        return modelAndView;
    }
}
